<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>检测是否为数组的两种方式</title>
</head>

<body>
    <script>
        //检测是否为数组的两种方式
        function reverse(arr) {
        //if(Array.isArray(arr))
            if (arr instanceof Array) {
                var newAr = [];
                for (var i = arr.length - 1; i >= 0; i--) {
                    newAr[newAr.length] = arr[i]
                }
                return newAr
            } else {
                return '参数必须是数组'
            }

        }
        var arr = reverse([1, 2, 3, 5, 3, 2, 4])
        var ae = reverse(1, 2, 3);
        console.log(ae);
        console.log(arr);
        var nw = reverse(['didi', 'meimei', 'puou'])
        console.log(nw);
        var arr = [];
        var obj = {};
        console.log(arr instanceof Array);
        console.log(obj instanceof Array)
        //第二种方式 Array.isArray(参数) H5新增的方法 IE9以上才支持
        console.log(Array.isArray(arr));
        console.log(Array.isArray(obj))
    </script>
</body>

</html>